# send_email.py

import argparse
import smtplib
from email.mime.text import MIMEText
from config import Config

def send_email(subject, body, recipient):
    msg = MIMEText(body, 'plain', 'utf-8')
    msg['Subject'] = subject
    msg['From'] = Config.SMTP_USERNAME
    msg['To'] = recipient

    try:
        with smtplib.SMTP(Config.SMTP_SERVER, Config.SMTP_PORT) as server:
            server.starttls()
            server.login(Config.SMTP_USERNAME, Config.SMTP_PASSWORD)
            server.sendmail(Config.SMTP_USERNAME, [recipient], msg.as_string())
        print(f'Email sent to {recipient}')
    except Exception as e:
        print(f'Failed to send email: {e}')

def main():
    parser = argparse.ArgumentParser(description='Send an email notification.')
    parser.add_argument('--subject', required=True, help='Email subject')
    parser.add_argument('--body', required=True, help='Email body')
    parser.add_argument('--recipient', required=True, help='Recipient email address')

    args = parser.parse_args()

    send_email(args.subject, args.body, args.recipient)

if __name__ == '__main__':
    main()
